<template>
  <el-row type="flex" align="middle" style="height: 40px;width:100%">
    <el-col :span="20"><div />{{ nodeData.name }}</el-col>
    <el-col :span="4"><div />
      <el-row type="flex" justify="end" align="middle">
        <el-col style="margin-right:30px" class="text-cut">{{ nodeData.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span class="el-dropdown-link" @click.stop>
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click.native="add">添加子部门</el-dropdown-item>
                <el-dropdown-item v-if="isroot" @click.native="edit">编辑部门</el-dropdown-item>
                <el-dropdown-item v-if="isroot" @click.native="del(nodeData.id)">删除部门</el-dropdown-item>
              </el-dropdown-menu>
            </template>

          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDept } from '@/api/department'
export default {
  name: 'TreeTools',
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    isroot: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {

    }
  },
  methods: {
    // 1.删除部门__________________________________________
    async del(id) {
      try {
        await this.$confirm('你确定删除此部门', '温馨提示', {
          type: 'warning'
        })
      } catch {
        return
      }
      await delDept(id)
      // 提示消息
      this.$message.success('删除部门成功')
      // 重新渲染
      this.$emit('getDeptList')
    },

    // 2. 添加部门__________________________________________
    add() {
      this.$emit('addDept', this.nodeData.id)
    },
    // 3. 修改部门__________________________________________
    edit() {
      this.$emit('editDept', this.nodeData.id)
    }
  }
}
</script>

<style>

</style>
